package com.jsh.controller;

import com.jsh.pojo.emailNumber;
import com.jsh.service.emailNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/emailNumber")
public class emailNumberController {
    @Autowired
    private emailNumberService emailNumberService;
    @RequestMapping("/list")
    public String list(Model model){
        List<emailNumber> emailNumbers = emailNumberService.selectAll();
        model.addAttribute("list",emailNumbers);
        return "list_emailNumber";
    }
    @RequestMapping("/toInsert")
    public String toInsert(){
        return "addEmailNumber";
    }
    @RequestMapping("/Insert")
    public String Insert(emailNumber record){
        int insert = emailNumberService.insert(record);
        return "redirect:/emailNumber/list";
    }
    @RequestMapping("/toUpdate")
    public String toUpdate(String username,Model model){
        emailNumber emailNumber = emailNumberService.selectByPrimaryKey(username);
        model.addAttribute("emailNumber",emailNumber);
        return "update_emailNumber";
    }
    @RequestMapping("/update")
    public String Update(emailNumber record){
        emailNumberService.updateByPrimaryKey(record);
        return "redirect:/emailNumber/list";
    }
    @RequestMapping("/delete")
    public String delete(String username){
        emailNumberService.deleteByPrimaryKey(username);
        return "redirect:/emailNumber/list";
    }
}
